home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / GMS / GMSDev / Source / C / Blitter / RamboWorm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-16  |  4.8 KB  |  191 lines

  1. /* Dice: 1> dcc -l0 -mD dpk.o RamboWorm.c -o RamboWorm
  2. **
  3. ** Blits a Worm to screen using a bob structure.  This version does not
  4. ** include the sound from the assembler version.
  5. */
  6.  
  7. #include <proto/dpkernel.h>
  8.  
  9. BYTE *ProgName      = "Rambo Worm";
  10. BYTE *ProgAuthor    = "Paul Manias";
  11. BYTE *ProgDate      = "January 1998";
  12. BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1998.  Freely distributable.";
  13. BYTE *ProgShort     = "Bob Demonstration.";
  14.  
  15. struct GScreen  *screen;
  16. struct Restore  *restore;
  17. struct Bob      *Worm;
  18. struct JoyData  *joydata;
  19. struct Picture  *background;
  20. struct FileName BackFile = { ID_FILENAME, "GMS:demos/data/PIC.Green" };
  21. struct FileName bobfile  = { ID_FILENAME, "GMS:demos/data/PIC.Rambo" };
  22.  
  23. WORD WormFrames[] = {
  24.     0,0,  32,0, 64,0,  96,0, 128,0, 160,0, 192,0, 224,0,
  25.   256,0, 288,0, 0,48, 32,48, 64,48,
  26.   -1,-1
  27. };
  28.  
  29. void Demo(void);
  30. void Wrap(struct Bob *);
  31.  
  32. /***************************************************************************/
  33.  
  34. void main(void) {
  35.   if (background = Load(&BackFile, ID_PICTURE)) {
  36.    if (screen = Get(ID_SCREEN)) {
  37.       CopyStructure(background, screen);
  38.       screen->Attrib = SCR_DBLBUFFER;
  39.  
  40.     if (Init(screen,NULL)) {
  41.      if (Copy(background->Bitmap,screen->Bitmap) IS ERR_OK) {
  42.         CopyBuffer(screen,BUFFER2,BUFFER1);
  43.  
  44.       if (restore = InitTags(screen,
  45.            TAGS_RESTORE, NULL,
  46.            RSA_Entries,  1,
  47.            TAGEND)) {
  48.  
  49.        if (Worm = InitTags(screen,
  50.            TAGS_BOB,      NULL,
  51.            BBA_GfxCoords, WormFrames,
  52.            BBA_Width,     32,
  53.            BBA_Height,    24,
  54.            BBA_XCoord,    150,
  55.            BBA_YCoord,    150,
  56.            BBA_Attrib,    BBF_RESTORE|BBF_GENMASKS|BBF_CLIP,
  57.              BBA_SourceTags, ID_PICTURE,
  58.              PCA_Source,     &bobfile,
  59.                PCA_BitmapTags, NULL,
  60.                BMA_MemType,    MEM_BLIT,
  61.                TAGEND, NULL,
  62.              TAGEND, NULL,
  63.            TAGEND)) {
  64.  
  65.         if (joydata = Get(ID_JOYDATA)) {
  66.            joydata->Port = 1;     /* Forces mouse control */
  67.  
  68.          if (Init(joydata, NULL)) {
  69.             Display(screen); 
  70.             Demo();
  71.          }
  72.         }
  73.        }
  74.       }
  75.      }
  76.     }
  77.    }
  78.   Free(joydata);
  79.   Free(Worm);
  80.   Free(restore);
  81.   Free(screen);
  82.   Free(background);
  83.   }
  84. }
  85.  
  86. /***************************************************************************/
  87.  
  88. void Demo(void)
  89. {
  90.   WORD anim = 0;
  91.   WORD fire = FALSE;
  92.   WORD x1,x2,y1,y2,ax1,ax2,ay1,ay2;
  93.  
  94.   do
  95.   {
  96.     Activate(restore); 
  97.     Draw(Worm);
  98.     WaitAVBL();
  99.     SwapBuffers(screen);
  100.  
  101.     /* Animate the Worm's movements */
  102.  
  103.     anim++;
  104.  
  105.     if (fire IS FALSE) {
  106.       if (anim > 5) {
  107.         anim = 0;
  108.         Worm->Frame++;
  109.         if (Worm->Frame > 9)
  110.            Worm->Frame = 0;
  111.       }
  112.     }
  113.     else if (anim > 1) {
  114.       anim = 0;
  115.       if (Worm->Frame < 10)
  116.          Worm->Frame = 9;
  117.  
  118.       Worm->Frame++;
  119.  
  120.       if (Worm->Frame > 12) {
  121.          if (joydata->Buttons & JD_LMB)
  122.             Worm->Frame = 11;
  123.          else {
  124.             Worm->Frame = 0;
  125.             fire = FALSE;
  126.          }
  127.       }
  128.     }
  129.  
  130.     /* Get the user input, wrap the bob around if out of bounds */
  131.  
  132.     Query(joydata);
  133.     Worm->XCoord += joydata->XChange;
  134.     Worm->YCoord += joydata->YChange;
  135.     Wrap(Worm);
  136.  
  137.     if (joydata->Buttons & JD_LMB) {
  138.        fire = TRUE;
  139.     }
  140.  
  141.   } while (!(joydata->Buttons & JD_RMB));
  142.  
  143.   /* Randomly perform a screen wipe effect before
  144.   ** exiting the demo.
  145.   */
  146.  
  147.   if (FastRandom(5) IS 4) {
  148.      ax1 = x1 = (screen->Width - screen->Height)/2;
  149.      ay1 = y1 = NULL;
  150.  
  151.      ax2 = x2 = screen->Width - ((screen->Width - screen->Height)/2);
  152.      ay2 = y2 = screen->Height;
  153.  
  154.      while (x1 < screen->Width) {
  155.         DrawLine(screen->Bitmap,x1,y1,x2,y2,0,0xffffffff);
  156.         DrawLine(screen->Bitmap,ax1,ay1,ax2,ay2,0,0xffffffff);
  157.         DrawLine(screen->Bitmap,x1+1,y1,x2+1,y2,0,0xffffffff);
  158.         DrawLine(screen->Bitmap,ax1+1,ay1,ax2+1,ay2,0,0xffffffff);
  159.         WaitAVBL();
  160.         SwapBuffers(screen);
  161.  
  162.         DrawLine(screen->Bitmap,x1,y1,x2,y2,0,0xffffffff);
  163.         DrawLine(screen->Bitmap,ax1,ay1,ax2,ay2,0,0xffffffff);
  164.         DrawLine(screen->Bitmap,x1+1,y1,x2+1,y2,0,0xffffffff);
  165.         DrawLine(screen->Bitmap,ax1+1,ay1,ax2+1,ay2,0,0xffffffff);
  166.         WaitAVBL();
  167.         SwapBuffers(screen);
  168.  
  169.         x1  += 2;  x2 += 2;
  170.         ax1 -= 2; ax2 -= 2;
  171.      }
  172.   }
  173. }
  174.  
  175. /*****************************************************************************
  176. ** Function: This function will wrap a bob to the other side of a screen if
  177. **           it leaves the bob's screen borders.
  178. **
  179. ** Synopsis: Wrap(Bob);
  180. */
  181.  
  182. void Wrap(struct Bob *bob)
  183. {
  184.   if (bob->XCoord < -bob->Width)  bob->XCoord = bob->DestBitmap->Width;
  185.   if (bob->YCoord < -bob->Height) bob->YCoord = bob->DestBitmap->Height;
  186.  
  187.   if (bob->XCoord > bob->DestBitmap->Width)  bob->XCoord = -bob->Width;
  188.   if (bob->YCoord > bob->DestBitmap->Height) bob->YCoord = -bob->Height;
  189. }
  190.  
  191.